﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;
using System.Text;

namespace tp
{
    public partial class index : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            if(rb2.Checked==true)
            {
            string str = "Data Source=pc.hstc.cn;Initial Catalog=dhd2014112142;User ID=2014112142;Password=19961124";
            string sql = "select Username,Userpassword from guanlogin where Username='" + username.Text + "'and Userpassword='" + userpassword.Text + "'";
            SqlConnection conn = new SqlConnection(str);
            conn.Open();
            SqlCommand cmd = new SqlCommand(sql, conn);
            SqlDataReader sdrr = cmd.ExecuteReader();
            if (sdrr.HasRows)
            {
                Response.Write("<script>alert('" + username.Text + "，你好!'); location.href = '/muguanli.aspx';</script>");
                Session["Userguanli"] = this.username.Text;
            }
            else
            {
                lbl.Text = "登录失败！";
            }
            conn.Close();
        }
            if (rb1.Checked == true)
            {
                string str = "Data Source=pc.hstc.cn;Initial Catalog=dhd2014112142;User ID=2014112142;Password=19961124";
                string sql = "select Username,Userpassword from tplogin where Username='" + username.Text + "'and Userpassword='" + userpassword.Text + "'";
                SqlConnection conn = new SqlConnection(str);
                conn.Open();
                SqlCommand cmd = new SqlCommand(sql, conn);
                SqlDataReader sdrr = cmd.ExecuteReader();
                if (sdrr.HasRows)
                {
                    Response.Write("<script>alert('" + username.Text + "，你好!'); location.href = '/guanliyuan.aspx';</script>");
                    Session["guanliyuan"] = this.username.Text;
                }
                else
                {
                    lbl.Text = "登录失败！";
                }
                conn.Close();
            }
        }
        protected void Timer1_Tick(object sender, EventArgs e)
        {
            this.lbltime.Text = System.DateTime.Now.ToString();
        }

        protected void ibtn_Click(object sender, ImageClickEventArgs e)
        {
            userpassword.TextMode = new TextBoxMode();
        }

        protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
        {
            if(rb2.Checked==true)
            {
            string strCn = "Data Source=pc.hstc.cn;Initial Catalog=dhd2014112142;User ID=2014112142;Password=19961124";
            SqlConnection cn = new SqlConnection(strCn);
            cn.Open();
            StringBuilder sb = new StringBuilder(1024);
            sb.Append("INSERT INTO guanlogin ");
            sb.Append("(Username, Userpassword) ");
            sb.Append("VALUES   (@Username,@Userpassword) ");
            SqlCommand cmd = new SqlCommand(sb.ToString(), cn);
            SqlParameter pmsUsername = new SqlParameter("@Username", this.username.Text);
            SqlParameter pmsUserpassword = new SqlParameter("@Userpassword", this.userpassword.Text);
            cmd.Parameters.Add(pmsUsername);
            cmd.Parameters.Add(pmsUserpassword);
            int iInsert = cmd.ExecuteNonQuery();
            if (iInsert < 1)
            {
                lbl.Text = "注册失败！";
            }
            else
            {
                Response.Write("<script>alert('注册成功！请填写相关信息！'); location.href = '/tianxie.aspx';</script>");
                Session["Usernew"] = this.username.Text;
            }
        }
            if (rb1.Checked == true)
            {
                string strCn = "Data Source=pc.hstc.cn;Initial Catalog=dhd2014112142;User ID=2014112142;Password=19961124";
                SqlConnection cn = new SqlConnection(strCn);
                cn.Open();
                StringBuilder sb = new StringBuilder(1024);
                sb.Append("INSERT INTO tplogin ");
                sb.Append("(Username, Userpassword) ");
                sb.Append("VALUES   (@Username,@Userpassword) ");
                SqlCommand cmd = new SqlCommand(sb.ToString(), cn);
                SqlParameter pmsUsername = new SqlParameter("@Username", this.username.Text);
                SqlParameter pmsUserpassword = new SqlParameter("@Userpassword", this.userpassword.Text);
                cmd.Parameters.Add(pmsUsername);
                cmd.Parameters.Add(pmsUserpassword);
                int iInsert = cmd.ExecuteNonQuery();
                if (iInsert < 1)
                {
                    lbl.Text = "注册失败！";
                }
                else
                {
                    Response.Write("<script>alert('注册成功！请再次登录！'); location.href = '/index.aspx';</script>");
                }
            }
        }
    }
}